<!DOCTYPE html>
<html lang="en" style="height:100%">

<head>
	<meta charset="UTF-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/style.css" />
	<link rel="stylesheet" type="text/css" href="../../css/yzl.css" />
	<style>
		body{
			height: 100vh;
			width: 100vw;
			background: linear-gradient(to bottom, #1b2e68,#00477a);
			color:#ffffff;
			position: relative;;
		}
		.more-login{
			bottom: 1%;
		}
	</style>
</head>

<body >
	<div class="login main-container" id="app" style="height: 80%;">
		<div class="login-title">欢迎来到扎堆</div>
		<div class="login-logo"><img src="../../image/logo_zhadui.png"></div>
		<div class="login-button" v-myclick="login_wx">
			<img v-src="'../../image/logon_wechat_2.png'">
			<span>微信快速登录</span>
		</div>
		<div class="more-login" v-myclick="pwdlogin">其它登录方式</div>
	</div>

</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/components.js"></script>

<script>
	var vm,
		wx,
		apiready = function () {
			setBSImg();
			new Vue({
				el: '#blank'
			})
			api.setStatusBarStyle({
				style: 'light'
			});
			wx = api.require('wx');

			setBSImg();
			initApp();
			doubleBack();
			api.parseTapmode();
			addListeners();
		};

	function initApp() {
		var isBigImg = Vue.BSImg == 'big';
		vm = new Vue({
			el: '#app',
			data: {
				isClose: true,
				BSImg: {
					big: isBigImg,
					small: !isBigImg
				},
				appInstalled: {
					wx: true,
					qq: true,
				},
				active: false
			},
			computed: {
				imgNum: function () {
					if (this.appInstalled.wx && this.appInstalled.qq) {
						return 3;
					} else if (!this.appInstalled.wx && !this.appInstalled.qq) {
						return 1;
					} else {
						return 2
					}
				},
				imgOneWidth: function () {
					switch (this.imgNum) {
						case 2:
							return '50%';
						case 3:
							return '33.3%';
						case 4:
							return '25%';
					}
				},
			},
			methods: {
				login_init: function (user, provider) {
					closeWin('index');
					setPrefs('user', user);
					setPrefs('token', user.token);
					setPrefs('imtoken', user.member_im_token);
					setPrefs('username', user.nickname);
					setPrefs('portrait', user.portrait);
					setPrefs('member_id', user.member_id);
					setPrefs('member_im_id', user.member_im_id);
					setPrefs('level_id', user.level_id);
					// setRongtoken();
					api.sendEvent({
						name: 'reLogin'
					});
					// openWin('../../index');
					if (user.is_set_pwd == 0) {
						// openWin('bindPassword')
						api.openWin({
							reload : true,
							name : 'bindPwd',
							url : 'bindPassword.html',
							vScrollBarEnabled : false,
							slidBackEnabled :false,
						});
						vm.clearMessage()
					}
					api.openWin({
						reload: true,
						name: 'index',
						url: '../../index.html',
						hScrollBarEnabled: false,
						slidBackEnabled: false,
					});

				},
				bindAccount: function (params, data, provider) {
					data['jpush_token'] = getPrefs('jpush_token') || '';
					if (hasPrefs('member_id')) {
						data.member_id = getPrefs('member_id');
					}
					var callback = function (ret) {
						if (ret.content.result) {
							vm.login_init(ret.content, provider);
						} else {
							openWin('../login/setInfo', params);
						}
					};
					pinet.post(URL.oauthLogin, data, callback);
				},
				login_wx: function () {
					wx.auth({}, function (ret, err) {
						if (!ret.status) {
						} else {
							wx.getToken({
								code: ret.code
							}, function (ret, err) {
								if (!ret.status) {
									// alert('获取授权 accessToken失败:' + err.code);
									api.toast({
										msg: '微信开小差了，请关闭app重新授权',
										duration: 3000,
										location: 'middle'
									});
									return false;
								} else {
									showProgress();
									wx.getUserInfo({
										accessToken: ret.accessToken,
										openId: ret.openId
									}, function (ret, err) {
										if (!ret.status) {
											// alert('获取用户信息失败:' + err.code);
											return false;
										} else {
											var params = {
												nickname: ret.nickname,
												sex: ret.sex,
												portrait: ret.headimgurl,
												openid: ret.openid,
												unionid: ret.unionid || '',
												oauth: 'Weixin'
											};
											var data = {
												openid: ret.openid,
												oauth: 'Weixin',
												unionid: ret.unionid || ''
											};
											vm.bindAccount(params, data, 'Weixin');
										}
									});
								}
							});
						}
					});
				},
				pwdlogin: function() {
					openWin('pwdLogin');
				}
			},
		})
	}

	function addListeners() {
	}

</script>

</html>